<%@page import="java.util.Date"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="controller.Paginate"%>
<%@page import="com.mongodb.DBObject"%>
<%@page import="com.mongodb.DBCursor"%>
<%
DBCursor cursor = (DBCursor)request.getAttribute("cursor");
String remove = (String) request.getAttribute("remove");
String falses = (String) request.getAttribute("falses");
String path = (String) request.getAttribute("path");
int total = Integer.parseInt((String) request.getAttribute("total"));
int p = Integer.parseInt((String)request.getAttribute("page"));
int np = Integer.parseInt((String)request.getAttribute("np"));
String work = (String)session.getAttribute("work");
String status = (String)request.getAttribute("status");
%>

<jsp:include page="layout/header.jsp">
	<jsp:param name="title" value="Manager source" />
	<jsp:param name="description" value="" />
	<jsp:param name="keywords" value="" />
	<jsp:param name="page" value="home" />
</jsp:include>

<div id="content">
        	<div id="content_inner">
            	<div id="maincontent">
                    <div id="domainmanager" class="clearafter">                    	
                        <h2 class="title">Manager source ( <span style="color: #D54E21"><%=work %></span> )
                        <%=status!=null&&status.equals("false")?"<br/><span style='color:red;'> ( Remove sitemap false ! ) </span>":"" %>
                        <%=status!=null&&status.equals("true")?"<br/><span style='color:blue;'> ( Remove sitemap success ! ) </span>":"" %>
                        </h2>
                        <div class="domain-toolbar title">
                        	<a href="/get-auto-content" style="float: left">Add target url to blog</a>
                        	<form method="get" action="">
                            	<div>
                                    <label>
                                        Name : 
                                        <input type="text" name="name"/>
                                    </label>
                                </div>
                                <button type="submit">Search</button>
                            </form>
                            <div class="clear:both;"></div>
                        </div>
                        <%
                        if(cursor.size()>0)
                        {
                        %>
                        <ul>
                        	<%
                        	while(cursor.hasNext())
                        	{
                        		DBObject dbObject = cursor.next();
                        		
                        	%>
                        	<%
	                            			long time = Long.parseLong(dbObject.get("timeend").toString())-new Date().getTime();
	                            			time = time/(24*60*60*1000);
	                            			if(time<0)time=0;
	                            	%>
	                            <li>
	                            	<a style="background-image: url('https://s2.googleusercontent.com/s2/favicons?domain_url=<%=dbObject.get("sitemap") %>');background-position: left center;background-repeat: no-repeat;display: inline-block;line-height: 16px;padding-left: 22px;text-decoration: none;" href="/edit-url?url=<%=URLEncoder.encode(dbObject.get("sitemap").toString())%>"><%=dbObject.get("sitemap") %></a>
	                                <div class="action">
	                                	<span><a href="/active-sitemap?sitemap=<%=URLEncoder.encode(dbObject.get("sitemap").toString()) %>&status=<%=(dbObject.get("status")==null||dbObject.get("status")!=null&&dbObject.get("status").toString().equals("false"))?"true":"false" %>" class="<%=(dbObject.get("status")==null||dbObject.get("status")!=null&&dbObject.get("status").toString().equals("false"))?"icon-disable":"icon-enable" %>"><%=(dbObject.get("status")==null||dbObject.get("status")!=null&&dbObject.get("status").toString().equals("false"))?"Deacive":"Active" %></a></span>
	                                    <span><a href="/remove-sitemap?sitemap=<%=URLEncoder.encode(dbObject.get("sitemap").toString()) %>" class="icon-trash" onclick="javascript:if(!confirm('Do you want remove url ?'))return false;">Remove</a></span>
	                                    <span><a href="/edit-url?url=<%=URLEncoder.encode(dbObject.get("sitemap").toString())%>" class="icon-screwdriver">Edit</a></span>
	                                </div>
	                            </li>
                            <%
                        	}
                            %>
                        </ul>
                        <%
                        } else {
                        %>
                        Currently you do not have any sitemap for <%=work %>. <a href="/get-auto-content" style="display: inline;">Click here</a>
                        <%
                        }
                        %>
                    </div>
                </div>
                <%
                if(total>20)
                {
                %>
                <%=Paginate.paginate(p,np,7,path) %>
                <%
                }
                %>
            </div>
        </div>
        
<%@ include file='/layout/footer.jsp'%>        